<include file="header" />
</head>
<body>
<div class="wraper">
	<div class="header flex-box">
		<a href="{BEESCRM::U('base/HduWaterFee/index',array('water_fee_id'=>$water_fee_id))}" class="iconfont icon-zuo"></a>
		<span class="text-center">{BEESCRM:$title}</span>
		<a href="{BEESCRM::U('base/HduWaterFee/log',array('water_fee_id'=>$water_fee_id))}" class="iconfont icon-wodejiaoyijilu text-right"></a>
	</div>
	<if condition="$show eq 0">
		<div class="container">
			<div class="label">
				<div class="label-btn text-16 text-center">请确认缴费信息</div>
				<div class="lists elemes">
					<p class="list-line flex-box between"><span class="field">缴费寝室</span><span class="auto-box text-right">{BEESCRM:$data.community_name}{BEESCRM:$data.building_name}{BEESCRM:$data.room_name}室</span></p>
					<p class="list-line flex-box between"><span class="field">缴费年月</span><span class="auto-box text-right">{BEESCRM:$data.year}年{BEESCRM:$data.month}月</span></p>
					<p class="list-line flex-box between"><span class="field">应缴费用</span><span class="text-red auto-box text-right">{BEESCRM:$data.need_fee}元</span></p>
				</div>
				<div class="label-btn text-16 text-center" id="charge">立即缴费<span class="iconfont icon-you pull-right text-gray"></span></div>
			</div>
		</div>
		<else/>
		<div class="container">
			<div class="label">
				<div class="label-mes flex-box">
					<p class="text-22 text-gray">暂无欠费信息</p>
				</div>
			</div>
		</div>
	</if>

	<div class="layer-wraper flex-box">
		<div class="main">
			<div class="lists lineheight15">
				<div class="label-btn text-16 text-center">请确认是否付款</div>
			</div>
			<div class="pop-btn">
				<a href="#" class="btn cancel">再看看</a>
				<a href="#" class="btn green-btn submit" data-list_id="{BEESCRM:$data.list_id}">确认付款</a>
			</div>
		</div>
	</div>

	<input type="hidden" value="{BEESCRM:$water_fee_id}" id="id">
</div>
</body>
</html>
<script src="/assets/base/hduwaterfee/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/hduwaterfee/js/jq.utils.js"></script>
<script src="/assets/bower_components/sweetalert/lib/sweet-alert.min.js"></script>
<link rel="stylesheet" href="/assets/bower_components/sweetalert/lib/sweet-alert.css?v={BEESCRM:$time}">
<script>
	$(function(){
		$('#charge').on('click',function(){
			$('.layer-wraper').addClass('layer-show');
		});

		$('.cancel').on('click',function(){
			$('.layer-wraper').removeClass('layer-show');
		});

		//提交订单
		var electricity_fee_id = $('#id').val();
		$(document).on('click','.submit',function(){
			var list_id = $(this).data('list_id');
			payorder(list_id);
		});

		function payorder(list_id){
			if(!list_id){
				$.alert('error','参数错误');
				return false;
			}
			$.ajax({
				'url': "/base/HduWaterFee/orderPay/water_fee_id/"+electricity_fee_id,
				'data': {'list_id':list_id},
				'dataType':'json',
				'type': 'POST',
				'async': false,
				success: function(data) {
					if (data.status == 'S') {
						var wxpay = $.parseJSON(data.wxpay);
						pay(wxpay);
					}else{
						$('.pop2').removeClass('layer-show');
						$.alert('error',data.message);
						return false;
					}
				}
			});
		}


		//微支付
		function pay(wxpay){
			if (typeof WeixinJSBridge == "undefined"){
				if( document.addEventListener ){
					document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
				}else if (document.attachEvent){
					document.attachEvent('WeixinJSBridgeReady', jsApiCall);
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
				}
			}else{
				WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						wxpay,
						function(res){
							WeixinJSBridge.log(res.err_msg);
							if(res.err_msg == "get_brand_wcpay_request:ok"){
								paySuccess();
							}else if(res.err_msg == "get_brand_wcpay_request:cancel"){
								$.alert('error','付款已取消');
								$('.layer-wraper').removeClass('layer-show');
								return false;
							}else{
								$.alert('error','调用微支付失败');
								$('.layer-wraper').removeClass('layer-show');
								return false;
							}
						}
				);
			}
		}

		function paySuccess(){
			var id = $('#id').val();
			location.href = "/base/HduWaterFee/log?water_fee_id="+id;
		}

		//页面刷新
		function reload(){
			setTimeout('location.reload()', 2000);
		}
	})
</script>